ADD O ET (file; set)
                                                                                    Pg 41-8
  
file        File            File from which to add current record
set
      String        Name of the set to which to add the record

ADD TO SET adds the current record of file to set. The set must already exist; if it does not, an error occurs. If a current record does not exist for file, ADD TO SET has no effect.

The example below deletes duplicate records from a file. The file contains information about people. A  For loop moves through all the records, comparing the current record to the previous record. If the first name and the last name are the same, then the record is added to a set. At the end of the loop, the set is made the current selection and the current selection is deleted:

CREATE EMPTY SET ([People]; "Duplicates") 
                                           `  Create an empty set for duplicate records 
ALL RECORDS ([People])   ` Select all records Sort the records by 
                                           ` ZIP, address, and name so that the 
                                           ` duplicates will be next to each other 
SORT SELECTION ([People]; [Addresses]ZIP; >; [Addresses]Address; >; [Addresses]Name; >) 
                                              ` Initialize variables that hold the 
$Name := [People]Name           ` fields from the previous record 
$Address := [People]Address 
$ZIP := [People]ZIP 
NEXT RECORD ([People])   ` Go to second record to compare to first 
`
For ($i; 2; Records in file ([People])) ` Loop thru records, start at 2 
        ` If the name, address, and ZIP are the same as the previous 
         ` record then it is a duplicate record.
   If (([People]Name = $Name) & ([People]Address = $Address) & ([People]ZIP = $ZIP)) 
      ADD TO SET ([People]; "Duplicates')
            ` Add current record (the duplicate) to set
    Else
                                          ` Save this record's name, address, and ZIP 
      $Name := [People]Name  ` for comparison with the next record 
      $Address := [People]Address 
      $ZIP := [People]ZIP
   End if
   NEXT RECORD ([People])   ` Move to the next record
End for
USE SET ("Duplicates")             ` Use duplicate records that were found
DELETE SELECTION ([People]) ` Delete the duplicate records
CLEAR SET ("Duplicates")         ` Remove the set from memory

See also: ALL ECORDS, CLEAR ET, CREATE ET, 
              CREATE MPTY ET, NEXT ECORD, 
              Records n election, SORT ELECTION